<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Http\Requests\Backend\LinkRequest;
use App\Models\Link;
use Illuminate\Http\Request;

class LinkController extends Controller
{
    public function index(){

        $links = Link::orderByDesc('id')->paginate(request('page_size', 10));

        return view('backend.link.index',compact('links'));
    }

    public function create(){

        return view('backend.link.create');
    }

    public function store(
        LinkRequest $request,
        Link $link
    ){
        $link->fill($request->filldata())->save();
        flash('添加成功', 'success');

        return back();
    }

    public function edit($id)
    {
        $link = Link::findOrFail($id);
        return view('backend.link.edit', compact('link'));
    }

    public function update(LinkRequest $request, $id)
    {
        $permission = Link::findOrFail($id);
        $permission->fill($request->filldata())->save();
        flash('编辑成功', 'success');

        return back();
    }

    public function destroy($id)
    {
        $link = Link::findOrFail($id);

        $link->delete();
        flash('删除成功', 'success');
        return back();
    }
}
